package com.woniuxy.mesboot.controller;

import com.woniuxy.mesboot.entity.MesMatInProduction;
import com.woniuxy.mesboot.service.MatInProductionService;
import com.woniuxy.mesboot.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("matInProduction")
public class MatInProductionController {
    @Resource
    private MatInProductionService matInProductionService;

    @GetMapping
    public Result queryAll() {
        List<MesMatInProduction> i = matInProductionService.selectAll();
        return Result.ok().data("list", i);

    }

    @PostMapping
    public Result insert(@RequestBody MesMatInProduction record) {
        int insert = matInProductionService.insertSelective(record);
        if (insert > 0) {
            return Result.ok("添加成功");
        } else {
            return Result.error("添加失败");
        }
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Long id) {
        int i = matInProductionService.deleteByPrimaryKey(id);
        if (i > 0) {
            return Result.ok("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }

    @GetMapping("{id}")
    public Result queryById(@PathVariable Long id) {
        MesMatInProduction mesMatInProduction = matInProductionService.selectByPrimaryKey(id);
        return Result.ok().data("item", mesMatInProduction);
    }

    @PutMapping
    public Result update(@RequestBody MesMatInProduction record) {
        int i = matInProductionService.updateByPrimaryKey(record);
        if (i > 0) {
            return Result.ok("修改成功");

        } else {
            return Result.error("修改失败");
        }
    }
}
